<template>
	<view v-if="!ShowData">
		<xbd-zwnz marginTop='200'></xbd-zwnz>
	</view>
	<view v-else class="result">
		<title :txt="title" />
		<view class="center">
			<view class="scor">

				<view><text class="num">{{score}}</text>分</view>

				<view class="right">
					<view class='rio1'>
					</view>
					正确
					<view class='rio2'>
					</view>错误
				</view>
			</view>
			<view class="tag">
				共{{topicList.length}}题 <text style="margin: 0 20rpx;">|</text>错{{topicList.length-true_count}}题<text
					style="margin: 0 20rpx;">|</text>用时： <text>{{fen}}分</text> {{miao}}秒
			</view>
			<view class="center-box">
				<view :class="['box', trueAnswer[index]==answer[index]  ? 'yes' : 'no']"
					v-for="(item,index) in topicList" :key='index' @click="choose(index)">
					{{index+1}}
				</view>
			</view>
		</view>
		<view class='exam'>
			<view style=" font-size: 32rpx; font-weight: 700; color: #000623;margin-bottom: 40rpx;">【{{showTopic.type}}题】</view>
			<view class="topic">
				<view style="margin-bottom: 60rpx; white-space: pre-line !important; word-break: break-all !important; word-wrap: break-word ;">
					<text style="margin-right: 10rpx;">{{inx+1}}.</text>
					{{showTopic.title}}
				</view>
				<view class="choose">
					<view class="box">A</view>
					<view class="right">
						{{showTopic.A}}
					</view>
				</view>
				<view class="choose">
					<view class="box">B</view>
					<view class="right">
						{{showTopic.B}}
					</view>
				</view>
				<view class="choose">
					<view class="box">C</view>
					<view class="right">
						{{showTopic.C}}
					</view>
				</view>
				<view class="choose">
					<view class="box">D</view>
					<view class="right">
						{{showTopic.D}}
					</view>
				</view>

			</view>
			<view>
				<text class="answer" style="margin-right: 60rpx;">正确答案：{{isAnswer}}</text>
				<text :class="['answer', isAnswer==userAnswer ? '' : 'yes']">你的答案：{{userAnswer||'-'}}</text>
			</view>
		</view>
	</view>

</template>

<script>
	import {
		Identify
	} from '@/api/index.js';
	import title from "@/components/iconTitle.vue";
	export default {
		name: "result",
		data() {
			return {
				id: '',
				title: '',
				fen: '',
				miao: '',
				score: '',
				topicList: [],
				trueAnswer: [],
				true_count: '',
				answer: [],
				inx:0,
				ShowData:false,
				showTopic: {
					A: "三",
					B: "四",
					C: "五",
					D: "六",
					title: "题目14",
					type: "单选"
				},
				isAnswer: '',
				userAnswer: '',

			};
		},
		components: {
			title,
		},
		methods: {
			choose(index) {
				this.inx = index
				this.showTopic = this.topicList[index]
				this.isAnswer = this.trueAnswer[index]
				this.userAnswer = this.answer[index]

			},
			async init() {
				const res = await Identify.getExamDetail(this.id)
				console.log(res)
					
				if(res.success){
					
					this.ShowData=true
					this.topicList = res.data.exam
					this.trueAnswer = res.data.true_answer
					this.answer = res.data.answer
					this.isAnswer = this.trueAnswer[0]
					this.userAnswer = this.answer[0]
					this.showTopic = this.topicList[0]
					this.title = res.data.name
					this.score = res.data.score
					this.true_count = res.data.true_count
					this.inx=0,
					this.fen = Math.trunc(res.data.use_time / 60)
					this.miao = res.data.use_time % 60
				}else{
					this.$showToast(res.msg);
				}
				
			},
		},
		onLoad(res) {
			this.id = res.id
			console.log(this.id)
			this.init()
		}

	};
</script>

<style lang="scss" scoped>
	.result {
		padding: 32rpx;

		.center {
			padding: 32rpx;
			background-color: #FFFFFF;
			margin: 30rpx 0;
			border-radius: 12rpx;

			.scor {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.num {
					font-size: 60rpx;
					font-family: DIN, DIN-Bold;
					font-weight: 700;
					text-align: left;
					color: #000623;
				}

				.right {
					display: flex;
					font-size: 26rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					color: #8890a5;

					.rio1 {
						margin: 10rpx 12rpx 0 30rpx;
						width: 12rpx;
						height: 12rpx;
						background: #2e73fc;
						border-radius: 50%;
					}

					.rio2 {
						margin: 10rpx 12rpx 0 30rpx;
						margin-top: 10rpx;
						width: 12rpx;
						height: 12rpx;
						background: #FCB94F;
						border-radius: 50%;
					}
				}
			}

			.tag {
				font-size: 26rpx;
				font-weight: 500;
				text-align: left;
				font-family: PingFang SC, PingFang SC-Medium;
				color: #8890a5;
				margin: 40rpx 0;
			}

			.center-box {
				display: flex;
				flex-wrap: wrap;

				.box {
					width: 60rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					color: #FFFFFF;
					margin-bottom: 20rpx;
					background-color: #fff;
					margin-right: 18rpx;
					border-radius: 12rpx;

					&:nth-child(8n) {
						margin-right: 0;
					}

				}

				.yes {
					background-color: #2E73FC;
				}

				.no {
					background-color: #FCB94F;
				}
			}
		}

		.exam {
			padding: 32rpx;
			background-color: #FFFFFF;
			border-radius: 12rpx;

			.answer {
				font-size: 30rpx;
				color: #2E73FC;
			}

			.yes {
				font-size: 30rpx;
				color: #FCB94F;
			}

			.topic {
				font-size: 32rpx;
				font-weight: 700;
				text-align: left;
				color: #000623;

			}

			.choose {
				display: flex;
				margin-bottom: 50rpx;

				.box {
					font-size: 36rpx;
					width: 70rpx;
					height: 70rpx;
					line-height: 70rpx;
					border-radius: 50%;
					background: #f5f7fb;
					margin-right: 30rpx;
					text-align: center;
				}

				.right {
					padding-top: 10rpx;
					font-size: 32rpx;
					width: 500rpx;
				}
			}
		}
	}
</style>
